
# Create your models here.
from django.db import models
from personal_center.models import User
from administrative.models import Company
from Administrative_office_system.utils.BaseModel import BaseModel, TimeStampFileName, ChatStampFileName, IssueStampFileName


class EvaluationOfMedicalEthics(BaseModel):
    STATE = (
        ('one', '科室意见'),
        ('two', '被考核人'),
        ('three', '办公室'),
        ('four', '考评小组'),
        ('seven', '待提交'),
        ('draft', '草稿'),
        ('five', '结束'),
        ('six', "撤回")
    )
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    apply_company_id = models.CharField(max_length=32, verbose_name='参评科室', default='')
    title = models.CharField(max_length=32, verbose_name='标题', default='')
    state = models.CharField('状态', max_length=10, choices=STATE, default='two')
    education = models.CharField(max_length=32, verbose_name='文化程度', default='')
    gender = models.CharField(max_length=10, choices=(('male', '男'), ('female', '女')), default='male', verbose_name='性别')
    birthday_date = models.CharField(max_length=100, verbose_name='出生日期', default='')
    employ_date = models.CharField(max_length=100, verbose_name='聘用日期', default='')
    job = models.CharField(max_length=32, verbose_name='岗位', default='')
    political_status = models.CharField(max_length=32, verbose_name='政治面貌', default='')
    professional_title = models.CharField(max_length=32, verbose_name='职称', default='')
    content = models.TextField(verbose_name='自我评价')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='evaluation_of_medical_ethics_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='evaluation_of_medical_ethics_already_users', blank=True)
    item_list = models.CharField(max_length=500, verbose_name='科室评分', default='')
    total_score = models.CharField(max_length=32, default='', verbose_name='总分')
    level = models.CharField(verbose_name='得分等级',
                             choices=(('best', '优秀'), ('good', '良好'), ('ordinary', '一般'), ('bad', '较差')), max_length=10,
                             default='')
    year = models.IntegerField(default=2022, verbose_name='年度')

    def get_state_str(self):
        if self.state == 'five':
            return '结束'
        elif self.state == 'draft':
            return '草稿'
        elif self.state == 'three':
            return '已提交'
        elif self.state == 'seven':
            return '待提交'
        else:
            return '审核中'

    def get_level_display(self):
        if self.level == 'best':
            return '优秀'
        elif self.level == 'good':
            return '良好'
        elif self.level == 'ordinary':
            return '一般'
        elif self.level == 'bad':
            return '较差'
        else:
            return ''


class EvaluationOpinion(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室意见'),
        ('two', '被考核人意见'),
        ('three', '考评小组意见'),
        ('eight', '结束'),
    )
    parent_id = models.ForeignKey(
        'EvaluationOfMedicalEthics',
        verbose_name="申请单",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_note = models.TextField(verbose_name="审批意见", blank=False, default='')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')


class EvaluationTeam(BaseModel):
    company = models.ForeignKey('administrative.Company', verbose_name="科室", blank=False, null=False, on_delete=models.CASCADE)
    team_leval = models.CharField(max_length=32, verbose_name='小组级别', default='')
    describe = models.CharField(max_length=32, verbose_name='描述', default='')